--图形库
local suit=require 'suit'
--local lfs=require("lfs")
local pressed
local video
local img
local img_rena
local audio
local clear_start_img=false
local bg
local mouse_state
--代码运行环境 是解释 还是嵌入在exe
local in_editor=true
--交换文件 python生成的
local swapBridge=""
local swapArray
global_game_path=""
function love.load()
	love.window.setTitle("gal工具箱")
	font=love.graphics.newFont("default.ttf",24)
	love.graphics.setFont(font)
	suit.theme.color.normal.fg = {255,255,255}
    suit.theme.color.hovered = {bg = {200,230,255}, fg = {0,0,0}}

	bg=love.graphics.newImage("bg.png")
	img=love.graphics.newImage("angel.png")
	img_rena=love.graphics.newImage("rena.png")
	audio=love.audio.newSource("bgm.mp3","stream")
	love.audio.play(audio)
	--swapBridge=load_swap()
	--print(swapBridge)
	--swapArray=Split(swapBridge,",")
end
function load_swap()
	txt=love.filesystem.read("swapBridge.txt")
	return txt 
end
function love.draw()
	love.graphics.draw(img,0.0)
	love.graphics.print({{0,0,0},"欢迎使用...\n 点击进入"},100,300)
	--进入主界面
	if clear_start_img then
		love.graphics.clear()
		love.graphics.draw(bg,0,0)
		love.graphics.draw(img_rena,600,300)
		suit.draw()
		--动态游戏按钮
		--[[ pos_y=100
		local button
		for k,v in pairs(swapArray) do
			button=suit.Button(v,0,pos_y,150,50)
			pos_y=pos_y+50
		end
		--调用ons
		if button.hit then
			local dir = ""
			--assuming that our path is full of lovely files (it should at least contain main.lua in this case)
			local files = love.filesystem.getDirectoryItems(dir)
			for k, file in ipairs(files) do
				print(k .. ". " .. file) --outputs something like "1. main.lua"
			end
		end ]]
	end
end

local input={text="请输入游戏路径"}
function love.update(dt)
	--循环播放启动音乐
	if not clear_start_img and not audio:isPlaying() then
		love.audio.play(audio)
	end
	local input_game_path=suit.Input(input,50,50,500,50)
	local label=suit.Label("No Game!",0,200,100,50)
	local btn_set=suit.Button("设置所有游戏根目录(路径不能有中文和特殊符号",300,0,300,50)
	local btn_about=suit.Button("关于",600,0,100,50)
	local btn_add=suit.Button("添加游戏",100,200,100,50)
	local btn_add_engine=suit.Button("添加引擎（启动器）",700,0)
	local btn=suit.Button("运行游戏",0,0,100,50)
	suit.Label("支持的引擎:Onscripter,krk,BkEngine",300,300,300,50)
	if btn_add_engine.hit then
		love.window.showMessageBox("title","请到浏览器下载,链接已经复制到粘贴板")
		love.system.setClipboardText("https://wwa.lanzoui.com/b016lqtfe 密码:6io4")
	end
	--设置路径
	if btn_set.hit then
		global_game_path=input.text--String_conversion(input.text)
		print(global_game_path)
	end
	--粘贴路径
	if input_game_path.hovered and mouse_state==2 then
		print("paste")
		input.text=love.system.getClipboardText()
	end
	if btn_about.hit then
		love.window.showMessageBox("关于","在windows更好的处理gal游戏，开发者128hh，联系方式qq 2439905184")
	end
	--运行游戏
	if btn.hit then
		pressed=true
		test=os.execute("cd C:/Users/11111/Documents/GitHub/gal-toolbox/64/bin &launchGame.cmd")
	end
end
function love.textinput(t)
	suit.textinput(t)
end
function love.mousepressed(x,y,button,istouch)
	mouse_state=button
	print(button)
	if button==1 then
		love.audio.stop()
		se=love.audio.newSource("se_pop.mp3","stream")
		love.audio.play(se)
		clear_start_img=true
	end
end